package guoanmaker.operator.business.controller;

import guoanmaker.operator.business.model.OperatorSpace;
import guoanmaker.operator.business.service.OperatorSpaceServiceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 *  
 *
 * @author huZhaoyu 
 * @ClassName: OperatorSpaceController
 * @Description: OperatorSpaceController 
 * @date 2017/6/28 下午5:01 
 */
@RestController
@RequestMapping(ApiController.OPERATOR_SPACE_URL)
public class OperatorSpaceController {
    private final OperatorSpaceServiceInterface operatorSpaceServiceInterface;

    public OperatorSpaceController(OperatorSpaceServiceInterface operatorSpaceServiceInterface) {
        this.operatorSpaceServiceInterface = operatorSpaceServiceInterface;
    }

    /** 
    * @Title: saveSpace
    * @Description: 新增/修改空间 
    * @param: OperatorSpace   
    * @return AjaxJson    
    * @throws 
    */
    @ApiOperation(value = "保存空间", notes = "新增/修改空间")
    @PostMapping(value = "saveSpace")
    public AjaxJson saveSpace(@RequestBody OperatorSpace operatorSpace) {
    	AjaxJson ajaxJson=new AjaxJson();
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorSpaceServiceInterface.saveSpace(operatorSpace));
    }

    /** 
     * @Title: deleteSpaceById
     * @Description: 根据Id删除空间
     * @param: String id  
     * @return AjaxJson 
     * @throws 
     */
    @ApiOperation(value = "删除空间", notes = "根据Id删除空间")
    @DeleteMapping(value = "delete/{id}")
    public AjaxJson deleteSpaceById(@PathVariable(value = "id") String id) {
    	AjaxJson ajaxJson=new AjaxJson();
        operatorSpaceServiceInterface.deleteSpaceById(id);
        return ajaxJson.setSuccess(true).setStatus(200).setData("数据删除成功!");
    }

    /**
     * @return OperatorSpace    
     * @Title: getSpaceById 
     * @Description: 根据Id查询空间
     * @param: String id   
     * @throws 
     */
    @ApiOperation(value = "根据Id查询空间", notes = "根据Id查询空间")
    @GetMapping(value = "getSpaceById")
    public AjaxJson getSpaceById(@RequestParam(value = "id") String id) {
    	AjaxJson ajaxJson=new AjaxJson();
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorSpaceServiceInterface.getSpaceById(id));
    }

    /**
     * @return AjaxJson   
     * @Title: getAllSpace
     * @Description: 查找所有空间 
     * @throws 
     */
    @ApiOperation(value = "查找所有空间", notes = "查找所有空间")
    @GetMapping(value = "getAllSpace")
    public AjaxJson getAllSpace() {
    	AjaxJson ajaxJson=new AjaxJson();
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorSpaceServiceInterface.getAllSpace());
    }

    /**
     * @return AjaxJson   
     * @Title: getAllSpaceByPage 
     * @Description: 查询所有空间并分页
     * @param: Integer page 页码
     * @param: Integer size 条数
     * @throws 
     */
    @ApiOperation(value = "分页查询空间", notes = "分页查询空间")
    @GetMapping(value = "getAllSpaceByPage")
    public AjaxJson getAllSpaceByPage(@RequestParam(value = "page", defaultValue = "0") Integer page,
                                           @RequestParam(value = "size", defaultValue = "10") Integer size) {
    	AjaxJson ajaxJson=new AjaxJson();
    	return ajaxJson.setSuccess(true).setStatus(200).setData(operatorSpaceServiceInterface.getAllSpaceByPage(page, size));
    }

    /**
     * @return AjaxJson   
     * @Title: getAllBySpaceTitleOrderByCreateDate 
     * @Description: 根据标题查询空间
     * @param: String spaceTitle 空间标题
     * @throws 
     */
    @ApiOperation(value = "根据标题查询空间", notes = "根据标题查询空间")
    @GetMapping(value = "getAllBySpaceTitleOrderByCreateDate")
    public AjaxJson getAllBySpaceTitleOrderByCreateDate(@RequestParam(value = "spaceTitle") String spaceTitle) {
    	AjaxJson ajaxJson=new AjaxJson();
    	return ajaxJson.setSuccess(true).setStatus(200).setData(operatorSpaceServiceInterface.getAllBySpaceTitleOrderByCreateDate(spaceTitle));
    }

}
